package com.example.customviewapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

public class RewriteMeasureView extends View {
    public RewriteMeasureView(Context context) {
        super(context);
    }

    public RewriteMeasureView(Context context, AttributeSet attributeSet){
        super(context,attributeSet);

    }

    public RewriteMeasureView(Context context, AttributeSet attributeSet,int defStyleAttr){
        super(context,attributeSet,defStyleAttr);

    }





    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int minSize = 100;
        int withMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);

        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);

        if(withMode == MeasureSpec.AT_MOST){
            if(width<minSize){
               width =  minSize;
            }

        }

        if(heightMode == MeasureSpec.AT_MOST){
           if(height<minSize){
               height = minSize;
           }
        }

        setMeasuredDimension(width,height);

    }

    @Override
    protected void onDraw(Canvas canvas) {

        int width = getMeasuredWidth();
        int height = getMeasuredHeight();

        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        canvas.drawRect(0,0,width,height,paint);
        canvas.save();
        canvas.restore();
    }
}
